﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void UBTXB(DataSet db)
        {
            int x = 5, y = 0;
            int idx = 1;
            DataRow dwWB = db.Tables[0].Rows[0];
            DataTable dtOutput = new DataTable();
            exAgent.SetCellValue(3, 1, "交库日期");
            exAgent.SetCellValue(3, 4, dwWB["WBEWBUCHDAT"].ToString());
            try
            {
                #region======Title===========                    
                exAgent.SetCellValue(x, idx++, "序号"); dtOutput.Columns.Add("SID", typeof(System.Decimal));
                exAgent.SetCellValue(x, idx++, "品名"); dtOutput.Columns.Add("WBEWART", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "花型色号"); dtOutput.Columns.Add("WBEWFARBE", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "匹号"); dtOutput.Columns.Add("WBEWSTKNR", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "匹长"); dtOutput.Columns.Add("WBEWMTR", typeof(System.Decimal));
                exAgent.SetCellValue(x, idx++, "匹重"); dtOutput.Columns.Add("WBEWGEW", typeof(System.Decimal));
                exAgent.SetCellValue(x, idx++, "工号(外加工)"); dtOutput.Columns.Add("WBEWBUCHBEN", typeof(System.String));
                #endregion
                #region======ConvertData===
                dtOutput.Merge(db.Tables[0]);
                foreach (DataRow rx in dtOutput.Rows)
                {
                    rx["WBEWMTR"] = Convert.ToInt32(rx["WBEWMTR"]) * 0.001;
                    rx["WBEWGEW"] = Convert.ToInt32(rx["WBEWGEW"]) * 0.001;
                }

                #endregion
                #region====Excel==========
                x++;
                int count = dtOutput.Rows.Count;
                exAgent.RangeCopy(x, 50, x + 1, x + count);
                exAgent.BatchConvert2Number(5, 5, count + 5, 6);
                exAgent.DataTableToExcel(dtOutput, x, 1);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }

    }
}
